﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Net.NetworkInformation;
using System.ServiceModel;
using System.ServiceModel.Description;
using demobackground.LuuDiemService1;

namespace demobackground
{
    public partial class ScorePage : PhoneApplicationPage
    {
        List<KetQua> ds;
        public ScorePage()
        {
            InitializeComponent();
            ds = new List<KetQua>();
            if (NetworkInterface.GetIsNetworkAvailable())
            {
                ServiceLuuDiemClient client = new ServiceLuuDiemClient();
                client.LayDuLieuCompleted += new EventHandler<LayDuLieuCompletedEventArgs>(client_LayDuLieuCompleted);
                client.LayDuLieuAsync();
                txtConnection.Opacity = 0;

            }
            else
            {
                txtConnection.Opacity = 1;
                txtConnection.Text = "Khong the ket noi internet de lay du lieu";
            }
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {

          
            
        }

        void client_LayDuLieuCompleted(object sender, LayDuLieuCompletedEventArgs e)
        {
          //  ds = e.Result.ToList();
            lbScore.ItemsSource = e.Result;
            if (e.Result.Count == 0)
            {
                imgSilver.Opacity = 0;
                imgBronze.Opacity = 0;
                imgGold.Opacity = 0;
            }
            else if (e.Result.Count == 1)
            {
                imgSilver.Opacity = 0;
                imgBronze.Opacity = 0;
                imgGold.Opacity = 1;
            }
            else if (e.Result.Count == 2)
            {
                imgSilver.Opacity = 1;
                imgBronze.Opacity = 0;
                imgGold.Opacity = 1;
            }
            else if (e.Result.Count >= 3)
            {
                imgSilver.Opacity = 1;
                imgBronze.Opacity = 1;
                imgGold.Opacity = 1;
            }
            
        }
    }
}